package com.blb.day13_demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.day13_demo.entity.Account;
import com.blb.day13_demo.mapper.AccountMapper;
import com.blb.day13_demo.service.ServiceA;
import com.blb.day13_demo.service.ServiceB;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ServiceAImpl extends ServiceImpl<AccountMapper, Account> implements ServiceA {

    @Autowired
    private ServiceB serviceB;

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void testA() {
        Account account = getById(1);
        account.setBalance(10000);
        updateById(account);
        //调用ServiceB的方法  Propagation.REQUIRED 内部方法事务会合并到外部事务中
        //REQUIRES_NEW testB在新事务中
        serviceB.testB();
        throw new RuntimeException("testA");
    }
}
